package live.yanxiaohui.demo.direct;

import com.rabbitmq.client.*;
import live.yanxiaohui.demo.util.RabitMQConnection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


public class Consumer2 {
    private static final String QUEUE_NAME = "game2";


    public static void main(String[] args) throws IOException, TimeoutException {
        // 1.创建连接
        Connection connection = RabitMQConnection.getConnection();
        final Channel channel = connection.createChannel();
        DefaultConsumer consumer = new DefaultConsumer(channel){

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String msg = new String(body);
                System.out.println("Consumer2:"+msg);
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        };
        channel.basicConsume(QUEUE_NAME, false, consumer);

    }
}
